<template>
    <Layout :style="{padding: '0 6px 6px'}">
        <!-- <BreadGuide /> -->
        <Header :style="{ borderTopLeftRadius: '10px',borderTopRightRadius: '10px'}">
            <DatePicker 
                v-model="QueryConstraint.dateRange" 
                type="daterange" 
                :options="DateOptions" 
                show-week-numbers split-panels placeholder="请选择查询日期"  
                format="yyyy-MM-dd"  
                @on-change="DateRangeChange"
                style="width: 220px"></DatePicker>

            <!-- <Select v-model.number="QueryConstraint.processingtype" style="width:150px;margin-left: 15px">
                <Option v-for="item in ProcessingTypes" :value="item.value" :key="item.value">{{ item.label }}</Option>
            </Select> -->

            <Select v-model.number="QueryType" style="width:150px;margin-left: 15px" @on-change="SelectQueryType">
                <Option v-for="item in QueryTypes" :value="item.value" :key="item.value">{{ item.label }}</Option>
            </Select>

            <Select v-model.number="QueryConstraint.periodtype" style="width:70px;margin-left: 15px" @on-change="SelectPeriodType">
                <Option v-for="item in PeriodTypes" :value="item.value" :key="item.value">{{ item.label }}</Option>
            </Select>

            <RadioGroup v-model.number="QueryConstraint.queryway" type="button" style="margin-left: 15px">
                <Radio :label="0">按全部</Radio>
                <Radio :label="1">仅相关</Radio>
            </RadioGroup>

            <ButtonGroup shape="circle"  style="margin-left: 20px">
                <Button type="error" @click="QueryResult" >查询</Button>
            </ButtonGroup>
            
            <Dropdown trigger="click"  @on-click="HandleData" style="margin-left: 20px">
                <Button type="primary">
                    数据处理
                    <Icon type="ios-arrow-down"></Icon>
                </Button>
                <DropdownMenu slot="list" :style="{top: '160px',left: '480px'}">
                    <DropdownItem name="ExporReport">导出报表</DropdownItem>
                </DropdownMenu>
            </Dropdown>
            <Input 
                v-model.trim="QueryConstraint.keyword" 
                @on-search="QueryResult"
                suffix="ios-search" 
                placeholder="请输入检索内容！" 
                :style="{width: 'auto',float: 'right',marginTop: '18px',marginRight: '0px',borderRadius : '30px'}" 
                :clearable="true" 
                :search="true" />
        </Header>
        <Content>
            <Content :style="{padding: '6px', minHeight: '280px', background: 'white',borderBottomLeftRadius: '10px',borderBottomRightRadius: '10px',height: '100%'}">
                <Table 
                    :loading="loading" 
                    border
                    show-summary
                    :height="tableHeight" 
                    ref="FundsReport"
                    size="small"
                    row-key="Id" 
                    :columns="Columns" 
                    :data="Reaport" 
                    :summary-method="handleSummary"
                    >
                </Table>
            </Content>
        </Content>
        <Footer :style="{ background: 'white',marginTop: '5px',padding: '15px 10px 10px',borderRadius: '10px'}">
            <Page 
                :style="{ textAlign:'right',marginTop: '0px',paddingRight: '0px',background: 'white'}"
                show-sizer 
                show-elevator 
                show-total 
                :total="Total"
                :page-size="QueryConstraint.pageSize"
                :page-size-opts="PageSizeOpts"
                @on-change="ChangePage"
                @on-page-size-change="ChangePageSize"/>
        </Footer>
    </Layout>
</template>
<script>
/* import BreadGuide from '@/components/Breadcrumb/index' */
import { GetBankReport,GetProjectReport,GetDatePickRange } from '@/axios/api/FundsReportAPI';
import { getToken } from "@/store/localStorage/cookies";
import qs from 'qs'

export default {
    name: 'FundsDailyReport',
    /* components: { BreadGuide }, */
    mounted:function() {
        
        switch(this.QueryType){
            case 0:
                this.Columns = this.BankColumns;
                GetBankReport(this.QueryConstraint).then(res => {
                    //console.log(res.list);
                    this.BankReport = res.list;
                    this.Total = res.totalCount;
                })
                break;
            case 1:
                this.Columns = this.ProjectColumns;
                GetProjectReport(this.QueryConstraint).then(res => {
                    //console.log(res.list);
                    this.ProjectReport = res.list;
                    this.Total = res.totalCount;
                })
                break;
            default:
                break;
        }

        GetDatePickRange().then(res => {
            this.DateOptions.shortcuts = res.map(item => {
                return {
                    text: item.text,
                    value: eval(item.value)
                }
            })
            //console.log(this.DateOptions.shortcuts);
        })
        this.tableHeight = window.innerHeight - 300
    },
    data () {
        return {
            QueryConstraint:{
                pageIndex: 1,
                pageSize: 15,
                keyword: '',
                processingtype: 1,
                queryway: 1,
                periodtype: 1,
                dateRange: [new Date(),new Date()], //减少一天算法 new Date(new Date().getTime() - 3600 * 1000 * 24)
            },
            PeriodTypes: [{
                value: 1,
                label: '日报'
            },{
                value: 2,
                label: '周报'
            },{
                value: 3,
                label: '月报'
            },{
                value: 4,
                label: '年报'
            },{
                value: 5,
                label: '自定义'
            }],
            QueryTypes: [{
                value: 0,
                label: '按银行口径'
            },{
                value: 1,
                label: '按项目口径'
            }],
            ProcessingTypes: [{
                value: 0,
                label: '预加工'
            },{
                value: 1,
                label: '实时加工'
            }],
            ProcessingType: 0,
            QueryType: 1,
            tableHeight: 810,
            loading: false,
            Total: 0,
            PageSizeOpts: [15,25,50,100],
            DateOptions:{
                shortcuts: [
                    /*{
                        text: '按周',
                        value (){
                            GetWeekRange().then(res => {
                               this.value = () => { return res }; 
                            });
                        }
                    },
                    {
                        text: '按月',
                        value () {
                            GetMontyRange().then(res => {
                                this.value = () => { return res }; 
                            });
                        }
                    },
                    {
                        text: '按年',
                        value () {
                            GetYearRange().then(res => {
                                this.value = () => { return res }; 
                            });
                        }
                    } */
                ],
                disabledDate (date) {
                    return date && date.valueOf() < new Date("2020-12-31");
                }
            },
            Columns: [],
            Reaport: [],
            BankColumns: [
                {
                    type: 'index',
                    key: 'Index',
                    title: '序号',
                    minWidth: 80,
                    align: 'center',
                    fixed:'left',
                },
                {
                    title: '账号尾号',
                    key: 'AccountTail',
                    minWidth: 100,
                    tree: true,
                    align:'left',
                    fixed:'left'
                },
                {
                    title: '银行名称',
                    key: 'BankName',
                    minWidth: 300,
                    align:'center',
                    fixed:'left',
                    render:(h,params)=>{
                        return h('div',{style: { textAlign:"left" }},params.row.BankName)
                    }
                },
                {
                    title: "期初数(单位：元)",
                    align: 'center',
                    children: [
                        {
                            title: '期初余额',
                            key: 'BeginBalance',
                            align:'center',
                            children: [
                            {
                                title: '现金',
                                key: 'BeginCash',
                                align:'center',
                                minWidth: 120,
                                render:(h,params)=>{
                                    return h('div',{style: { textAlign:"left" }},params.row.BeginCash)
                                }
                            },
                            {
                                title: '商票',
                                key: 'BeginCommercialTicket',
                                align:'center',
                                minWidth: 120,
                                render:(h,params)=>{
                                    return h('div',{style: { textAlign:"left" }},params.row.BeginCommercialTicket)
                                }
                            },
                            {
                                title: '小计',
                                key: 'BeginBalance',
                                align:'center',
                                minWidth: 120,
                                render:(h,params)=>{
                                    return h('div',{style: { textAlign:"left" }},params.row.BeginBalance)
                                }
                            }]
                            
                        },
                        {
                            title: '冻结资金',
                            key:'BeginFreezeMoney',
                            align:'center',
                            minWidth: 120,
                            render:(h,params)=>{
                                return h('div',{style: { textAlign:"left" }},params.row.BeginFreezeMoney)
                            }
                        },
                        {
                            title: '可用余额',
                            key:'BeginFlowBalance',
                            align:'center',
                            minWidth: 120,
                            render:(h,params)=>{
                                return h('div',{style: { textAlign:"left" }},params.row.BeginFlowBalance)
                            }
                        }
                    ]
                },
                {
                    title: '本期收入(单位：元)',
                    align:'center',
                    children:[
                        {
                            title: '内部往来',
                            key: 'IncomeInnerTransaction',
                            align: 'center',
                            minWidth: 120,
                            render:(h,params)=>{
                                return h('div',{style: { textAlign:"left" }},params.row.IncomeInnerTransaction)
                            }
                        },
                        {
                            title: '房产往来',
                            key: 'IncomeRealEstateTransaction',
                            align: 'center',
                            minWidth: 120,
                            render:(h,params)=>{
                                return h('div',{style: { textAlign:"left" }},params.row.IncomeAdvanceFund)
                            }
                        },
                        {
                            title: '垫资款',
                            key: 'IncomeAdvanceFund',
                            align: 'center',
                            minWidth: 120,
                            render:(h,params)=>{
                                return h('div',{style: { textAlign:"left" }},params.row.IncomeAdvanceFund)
                            }
                        },
                        {
                            title: '保证金',
                            key: 'IncomeSecurity',
                            align: 'center',
                            minWidth: 120,
                            render:(h,params)=>{
                                return h('div',{style: { textAlign:"left" }},params.row.IncomeSecurity)
                            }
                        },
                        {
                            title: '银行借款',
                            key: 'IncomeBankLoan',
                            align: 'center',
                            minWidth: 120,
                            render:(h,params)=>{
                                return h('div',{style: { textAlign:"left" }},params.row.IncomeBankLoan)
                            }
                        },
                        {
                            title: '工程款',
                            key: 'IncomeProject',
                            align: 'center',
                            minWidth: 120,
                            render:(h,params)=>{
                                return h('div',{style: { textAlign:"left" }},params.row.IncomeProject)
                            }
                        },
                        {
                            title: '管理费',
                            key: 'IncomeManage',
                            align: 'center',
                            minWidth: 120,
                            render:(h,params)=>{
                                return h('div',{style: { textAlign:"left" }},params.row.IncomeManage)
                            }
                        },
                        {
                            title: '税金',
                            key: 'IncomeTax',
                            align: 'center',
                            minWidth: 120,
                            render:(h,params)=>{
                                return h('div',{style: { textAlign:"left" }},params.row.IncomeTax)
                            }
                        },
                        {
                            title: '其他',
                            key: 'IncomeOther',
                            align: 'center',
                            minWidth: 120,
                            render:(h,params)=>{
                                return h('div',{style: { textAlign:"left" }},params.row.IncomeOther)
                            }
                        },
                        {
                            title: '收入合计',
                            key: 'Income',
                            align: 'center',
                            minWidth: 120,
                            render:(h,params)=>{
                                return h('div',{style: { textAlign:"left" }},params.row.Income)
                            }
                        }
                    ]
                    
                },
                {
                    title: '本期支出(单位：元)',
                    align:'center',
                    children:[
                        {
                            title: '内部往来',
                            key: 'CostInnerTransaction',
                            align: 'center',
                            minWidth: 120,
                            render:(h,params)=>{
                                return h('div',{style: { textAlign:"left" }},params.row.CostInnerTransaction)
                            }
                        },
                        {
                            title: '房产往来',
                            key: 'CostRealEstateTransaction',
                            align: 'center',
                            minWidth: 120,
                            render:(h,params)=>{
                                return h('div',{style: { textAlign:"left" }},params.row.CostRealEstateTransaction)
                            }
                        },
                        {
                            title: '垫资款',
                            key: 'CostAdvanceFund',
                            align: 'center',
                            minWidth: 120,
                            render:(h,params)=>{
                                return h('div',{style: { textAlign:"left" }},params.row.CostAdvanceFund)
                            }
                        },
                        {
                            title: '保证金',
                            key: 'IncomeSecurity',
                            align: 'center',
                            minWidth: 120,
                            render:(h,params)=>{
                                return h('div',{style: { textAlign:"left" }},params.row.IncomeSecurity)
                            }
                        },
                        {
                            title: '银行借款',
                            key: 'CostBankLoan',
                            align: 'center',
                            minWidth: 120,
                            render:(h,params)=>{
                                return h('div',{style: { textAlign:"left" }},params.row.CostBankLoan)
                            }
                        },
                        {
                            title: '利息',
                            key: 'CostInterest',
                            align: 'center',
                            minWidth: 120,
                            render:(h,params)=>{
                                return h('div',{style: { textAlign:"left" }},params.row.CostInterest)
                            }
                        },
                        {
                            title: '材料款',
                            key: 'CostMaterial',
                            align: 'center',
                            minWidth: 120,
                            render:(h,params)=>{
                                return h('div',{style: { textAlign:"left" }},params.row.CostMaterial)
                            }
                        },
                        {
                            title: '人工费',
                            key: 'CostLabor',
                            align: 'center',
                            minWidth: 120,
                            render:(h,params)=>{
                                return h('div',{style: { textAlign:"left" }},params.row.CostLabor)
                            }
                        },
                        {
                            title: '管理费',
                            key: 'CostManage',
                            align: 'center',
                            minWidth: 120,
                            render:(h,params)=>{
                                return h('div',{style: { textAlign:"left" }},params.row.CostManage)
                            }
                        },
                        {
                            title: '税金',
                            key: 'CostTax',
                            align: 'center',
                            minWidth: 120,
                            render:(h,params)=>{
                                return h('div',{style: { textAlign:"left" }},params.row.CostTax)
                            }
                        },
                        {
                            title: '报销款',
                            key: 'CostReimbursement',
                            align: 'center',
                            minWidth: 120,
                            render:(h,params)=>{
                                return h('div',{style: { textAlign:"left" }},params.row.CostReimbursement)
                            }
                        },
                        {
                            title: '其他',
                            key: 'CostOther',
                            align: 'center',
                            minWidth: 120,
                            render:(h,params)=>{
                                return h('div',{style: { textAlign:"left" }},params.row.CostOther)
                            }
                        },
                        {
                            title: '支出合计',
                            key: 'Cost',
                            align: 'center',
                            minWidth: 120,
                            render:(h,params)=>{
                                return h('div',{style: { textAlign:"left" }},params.row.Cost)
                            }
                        }
                    ]
                },
                {
                    title: "期末数(单位：元)",
                    align: "center",
                    children: [
                        {
                            title: '期末余额',
                            key: 'EndBalance',
                            align:'center',
                            children: [
                            {
                                title: '现金',
                                key: 'EndCash',
                                align:'center',
                                minWidth: 120,
                                render:(h,params)=>{
                                    return h('div',{style: { textAlign:"left" }},params.row.EndCash)
                                }
                            },
                            {
                                title: '商票',
                                key: 'EndCommercialTicket',
                                align:'center',
                                minWidth: 120,
                                render:(h,params)=>{
                                    return h('div',{style: { textAlign:"left" }},params.row.EndCommercialTicket)
                                }
                            },
                            {
                                title: '小计',
                                key: 'EndBalance',
                                align:'center',
                                minWidth: 120,
                                render:(h,params)=>{
                                    return h('div',{style: { textAlign:"left" }},params.row.EndBalance)
                                }
                            }]
                        },
                        {
                            title: '冻结资金',
                            key:'EndFreezeMoney',
                            align:'center',
                            minWidth: 120,
                            render:(h,params)=>{
                                return h('div',{style: { textAlign:"left" }},params.row.EndFreezeMoney)
                            }
                        },
                        {
                            title: '可用余额',
                            key:'EndFlowBalance',
                            align:'center',
                            minWidth: 120,
                            render:(h,params)=>{
                                return h('div',{style: { textAlign:"left" }},params.row.EndFlowBalance)
                            }
                        }
                    ]
                }
            ],
            BankReport: [],
            ProjectColumns: [
                {
                    type: 'index',
                    key: 'Index',
                    title: '序号',
                    minWidth: 80,
                    align: 'center',
                    fixed:'left',
                },
                {
                    title: '项目编码',
                    key: 'NumCode',
                    tree: true,
                    minWidth: 150,
                    fixed:'left',
                },
                {
                    title: '项目名称',
                    key: 'ProjectName',
                    minWidth: 250,
                    align: 'center',
                    fixed:'left',
                    render:(h,params)=>{
                        return h('div',{style: { textAlign:"left" }},params.row.ProjectName)
                    }
                },
                {
                    title: '期初数',
                    align: 'center',
                    children: [
                         {
                            title: '期初余额',
                            key: 'BeginBalance',
                            align: 'center',
                            minWidth: 120,
                            render:(h,params)=>{
                                return h('div',{style: { textAlign:"left" }},params.row.BeginBalance)
                            }
                        },
                        {
                            title: '冻结资金',
                            key:'BeginFreezeMoney',
                            align: 'center',
                            minWidth: 120,
                            render:(h,params)=>{
                                return h('div',{style: { textAlign:"left" }},params.row.BeginFreezeMoney)
                            }
                        },
                        {
                            title: '可用余额',
                            align: 'center',
                            children: [
                                {
                                    title: '合计',
                                    key:'BeginFlowBalance',
                                    align: 'center',
                                    minWidth: 120,
                                    render:(h,params)=>{
                                        return h('div',{style: { textAlign:"left" }},params.row.BeginFlowBalance)
                                    }
                                },
                                {
                                    title: '现金余额',
                                    key:'BeginCashBalance',
                                    align: 'center',
                                    minWidth: 120,
                                    render:(h,params)=>{
                                        return h('div',{style: { textAlign:"left" }},params.row.BeginCashBalance)
                                    }
                                },
                                {
                                    title: '商票余额',
                                    key:'BeginCommercialTicket',
                                    align: 'center',
                                    minWidth: 120,
                                    render:(h,params)=>{
                                        return h('div',{style: { textAlign:"left" }},params.row.BeginCommercialTicket)
                                    }
                                },
                                {
                                    title: '工抵房余额',
                                    key:'BeginGongDiFang',
                                    align: 'center',
                                    minWidth: 120,
                                    render:(h,params)=>{
                                        return h('div',{style: { textAlign:"left" }},params.row.BeginGongDiFang)
                                    }
                                },
                            ]
                        }
                    ]
                },
                {
                    title: '本期收入',
                    align: 'center',
                    children:[
                        {
                            title: '收入小计',
                            key: 'Income',
                            align: 'center',
                            minWidth: 120,
                            render:(h,params)=>{
                                return h('div',{style: { textAlign:"left" }},params.row.Income)
                            }
                        },
                        {
                            title: '现金收入',
                            key: 'IncomeCash',
                            align: 'center',
                            minWidth: 120,
                            render:(h,params)=>{
                                return h('div',{style: { textAlign:"left" }},params.row.IncomeCash)
                            }
                        },
                        {
                            title: '商票收入',
                            key: 'IncomeCommercialTicket',
                            align: 'center',
                            minWidth: 120,
                            render:(h,params)=>{
                                return h('div',{style: { textAlign:"left" }},params.row.IncomeCommercialTicket)
                            }
                        },
                        
                    ]
                },
                {
                    title: '本期支出金额',
                    align: 'center',
                    children:[
                        {
                            title: '支出小计',
                            key: 'Cost',
                            align: 'center',
                            minWidth: 120,
                            render:(h,params)=>{
                                return h('div',{style: { textAlign:"left" }},params.row.Cost)
                            }
                        },
                        {
                            title: '现金支出',
                            key: 'CostCash',
                            align: 'center',
                            minWidth: 120,
                            render:(h,params)=>{
                                return h('div',{style: { textAlign:"left" }},params.row.CostCash)
                            }
                        },
                        {
                            title: '商票支出',
                            key: 'CostCommercialTicket',
                            align: 'center',
                            minWidth: 120,
                            render:(h,params)=>{
                                return h('div',{style: { textAlign:"left" }},params.row.CostCommercialTicket)
                            }
                        },
                    ]
                },
                {
                    title: '期末数',
                    align: 'center',
                    children: [
                        {
                            title: '期末余额',
                            key: 'EndBalance',
                            align: 'center',
                            minWidth: 120,
                            render:(h,params)=>{
                                return h('div',{style: { textAlign:"left" }},params.row.EndBalance)
                            }
                        },
                        {
                            title: '冻结资金',
                            key:'EndFreezeMoney',
                            align: 'center',
                            minWidth: 120,
                            render:(h,params)=>{
                                return h('div',{style: { textAlign:"left" }},params.row.EndFreezeMoney)
                            }
                        },
                        {
                            title: '可用余额',
                            align: 'center',
                            children: [
                                {
                                    title: '合计',
                                    key:'EndFlowBalance',
                                    align: 'center',
                                    minWidth: 120,
                                    render:(h,params)=>{
                                        return h('div',{style: { textAlign:"left" }},params.row.EndFlowBalance)
                                    }
                                },
                                {
                                    title: '现金余额',
                                    key:'EndCashBalance',
                                    align: 'center',
                                    minWidth: 120,
                                    render:(h,params)=>{
                                        return h('div',{style: { textAlign:"left" }},params.row.EndCashBalance)
                                    }
                                },
                                {
                                    title: '商票余额',
                                    key:'EndCommercialTicket',
                                    align: 'center',
                                    minWidth: 120,
                                    render:(h,params)=>{
                                        return h('div',{style: { textAlign:"left" }},params.row.EndCommercialTicket)
                                    }
                                },
                                {
                                    title: '工抵房余额',
                                    key:'EndGongDiFang',
                                    align: 'center',
                                    minWidth: 120,
                                    render:(h,params)=>{
                                        return h('div',{style: { textAlign:"left" }},params.row.EndGongDiFang)
                                    }
                                }
                            ]
                        }
                    ]
                }
            ],
            ProjectReport: []
        }
    },
    methods:{
        ChangePage(pageIndex){
            //console.log(pageIndex)
            this.QueryConstraint.pageIndex = pageIndex;
            
            if(this.QueryType == 0){
                this.loading = true;
                GetBankReport(this.QueryConstraint).then(res => {
                    //console.log(res.list);
                    this.Reaport = res.list;
                    this.Total = res.totalCount;
                    this.loading = false;
                })
            }

            if(this.QueryType == 1){
                this.loading = true;
                GetProjectReport(this.QueryConstraint).then(res => {
                    //console.log(res.list);
                    this.Reaport = res.list;
                    this.Total = res.totalCount;
                    this.loading = false;
                })
            }
        },
        ChangePageSize(pageSize){
            this.QueryConstraint.pageSize = pageSize;

            if(this.QueryType == 0){
                this.loading = true;
                GetBankReport(this.QueryConstraint).then(res => {
                    //console.log(res.list);
                    this.Reaport = res.list;
                    this.Total = res.totalCount;
                    this.loading = false;
                })
            }

            if(this.QueryType == 1){
                this.loading = true;
                GetProjectReport(this.QueryConstraint).then(res => {
                    //console.log(res.list);
                    this.Reaport = res.list;
                    this.Total = res.totalCount;
                    this.loading = false;
                })
            }
        },
        SelectQueryType(value){
            switch(value){
                case 0:
                    this.Columns = this.BankColumns;
                    this.loading = true;
                    GetBankReport(this.QueryConstraint).then(res => {
                        //console.log(res.list);
                        this.Reaport = res.list;
                        this.Total = res.totalCount;
                        this.loading = false;
                    })
                    break;
                case 1:
                    this.Columns = this.ProjectColumns;
                    this.loading = true;
                    GetProjectReport(this.QueryConstraint).then(res => {
                        //console.log(res.list);
                        this.Reaport = res.list;
                        this.Total = res.totalCount;
                        this.loading = false;
                    })
                    break;
                default:
                    break;
            }
        },
        SelectPeriodType(value){
            switch(value){
                case 1:
                    this.QueryConstraint.periodtype = 1
                    break;
                case 2:
                    this.QueryConstraint.periodtype = 2
                    break;
                case 3:
                    this.QueryConstraint.periodtype = 3
                    break;
                case 4:
                    this.QueryConstraint.periodtype = 4
                    break;
                case 5:
                    this.QueryConstraint.periodtype = 5
                    break;
                default:
                    break;
            }
        },
        handleSummary({ columns, data }){
            const sums = {};
            columns.forEach((column, index) => {
                const key = column.key;
                if (index === 2) {
                    sums[key] = {
                        key,
                        value: '合计',
                    };
                    return;
                }

                const values = data.map(item => Number(item[key]));
                if (!values.every(value => isNaN(value)) && index > 2) {
                    const v = values.reduce((prev, curr) => {
                        const value = Number(curr);
                        if (!isNaN(value)) {
                            return prev + curr;
                        } else {
                            return prev;
                        }
                    }, 0);
                    sums[key] = {
                        key,
                        value: v.toFixed(2) 
                    };
                } else {
                    sums[key] = {
                        key,
                        value: ''
                    };
                }
            });

            return sums;
        },
        QueryResult(){
            if(this.QueryType == 0){
                this.loading = true;
                //console.log(this.QueryConstraint);
                GetBankReport(this.QueryConstraint).then(res => {
                    //console.log(res.list);
                    this.Reaport = res.list;
                    this.Total = res.totalCount;
                    this.loading = false;
                })
            }

            if(this.QueryType == 1){
                this.loading = true;
                //console.log(this.QueryConstraint);
                GetProjectReport(this.QueryConstraint).then(res => {
                    //console.log(res.list);
                    this.Reaport = res.list;
                    this.Total = res.totalCount;
                    this.loading = false;
                })
            }
        },
        DateRangeChange(){
            var dayCount = (Math.abs(this.QueryConstraint.dateRange[1] - this.QueryConstraint.dateRange[0]))/1000/60/60/24
            
            switch(dayCount){
                case 0:
                    this.QueryConstraint.periodtype = 1;
                    break;
                case 6:
                    this.QueryConstraint.periodtype = 2;
                    break;
                case 27:
                    this.QueryConstraint.periodtype = 3;
                    break;
                case 28:
                    this.QueryConstraint.periodtype = 3;
                    break;
                case 29:
                    this.QueryConstraint.periodtype = 3;
                    break;
                case 30:
                    this.QueryConstraint.periodtype = 3;
                    break;
                case 364:
                    this.QueryConstraint.periodtype = 4;
                    break;
                default:
                    this.QueryConstraint.periodtype = 5;
            }
        },
        HandleData(name){
            if(name == "ExporReport"){

                this.$Spin.show();

                var accessToken = getToken();

                let link = document.createElement("a");

                if(this.QueryType == 0){
                    var bankQueryInfo = this.QueryConstraint
                    bankQueryInfo.pageIndex = 1;
                    bankQueryInfo.pageSize = this.Total;
                    bankQueryInfo.processingtype = 0;
                    link.href = process.env.VUE_APP_BASE_API+"/FundsReport/ExportData?BankOrProject=Bank&AccessToken=" 
                                    + accessToken + "&" + qs.stringify(bankQueryInfo, { arrayFormat: 'brackets' }); // 本窗口打开下载
                    //console.log(this.QueryConstraint)
                }
                
                if(this.QueryType == 1){
                    var projectQueryInfo = this.QueryConstraint
                    projectQueryInfo.pageIndex = 1;
                    projectQueryInfo.pageSize = this.Total;
                    projectQueryInfo.processingtype = 0;
                    link.href = process.env.VUE_APP_BASE_API+"/FundsReport/ExportData?BankOrProject=Project&AccessToken=" 
                                    + accessToken + "&" + qs.stringify(projectQueryInfo, { arrayFormat: 'brackets' }); // 本窗口打开下载
                    //console.log(this.QueryConstraint)
                }

                link.download = "导出文件.xlsx";

                document.body.appendChild(link);

                link.click();
                
                document.body.removeChild(link);

                this.$Spin.hide();

            }
        }
    }
}
</script>
<style scoped>

</style>